package com.lecture.java8.excel.dyr;

import com.alibaba.excel.EasyExcel;
import com.lecture.java8.excel.DemoDataListener;
import com.lecture.java8.excel.dyr.model.Finance0413;
import com.lecture.java8.excel.model.Result;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class Test0413 {
    public static void main(String[] args) {
        String dataResultFileName = "D:\\study\\tmp\\0413\\【更新2021】各省互联网普及率 2011-2021.xlsx";
        DemoDataListener<Result> dataResultListener = new DemoDataListener<>();
        EasyExcel.read(dataResultFileName, Result.class,dataResultListener).sheet().doRead();
        List<Result> resultList = dataResultListener.getDataList();

        Map<String, String> resultMap = resultList.stream().collect(Collectors.toMap(r -> r.getProvince() + "-" + r.getYear(), Result::getIndex));


        Set<String> set = new HashSet<>();
        String dataFileName = "D:\\study\\tmp\\0413\\正在使用的.xlsx";
        DemoDataListener<Finance0413> dataListener = new DemoDataListener<>();
        EasyExcel.read(dataFileName, Finance0413.class,dataListener).sheet().doRead();
        List<Finance0413> financeList = dataListener.getDataList();
        for (Finance0413 finance : financeList) {
            if (finance.getO() == null) {
                System.out.println("");
                continue;
            }
            String province = finance.getO().replace("省", "");
            Long year = finance.getB();
            String key = province + "-" + year;
            finance.setAr(resultMap.get(key));
        }


        EasyExcel.write("D:\\study\\tmp\\0413\\result.xlsx", Finance0413.class)
                .sheet("a").doWrite(financeList);

    }
}
